package cn.hfjava.kz.config.properties;

import jakarta.annotation.Resource;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties(prefix = "md")
@Setter
@Getter
@NoArgsConstructor
@Slf4j
public class MdUploadProperties {

    @Resource
    private Environment env;

    /**
     * Windows操作系统保存上传文件路径
     */
    private String windowsProfile;

    /**
     * Linux(Ubuntu Linux、Debian Linux、CentOS Linux、AliOS Linux、Fedora etc.)操作系统保存上传文件路径
     */
    private String linuxProfile;

    /**
     * 访问静态资源基路径
     */
    private String baseUrl;

    /**
     * 访问静态资源文件路径
     */
    private String assetsUrl;

    /**
     * 根据当前操作系统名称获取保存上传文件的路径
     */
    public String getUploadPath() {
        String osName = env.getProperty("os.name");
        log.info("当前操作系统名称是：{}", osName);
        if(osName.startsWith("Windows")) {
            return windowsProfile;
        } else {
            return linuxProfile;
        }
    }
}